package com.zwh.common.persistence;

import java.io.Serializable;

import com.fasterxml.jackson.annotation.JsonInclude;

/**
 * @Author zwh
 * @Date 2019/9/25 15:04
 **/
@JsonInclude(JsonInclude.Include.ALWAYS)
public class ReturnObject<T> implements Serializable {
    private static final long serialVersionUID = 1L;

    private T data;
    private String message = "";

    private String result = "true"; // true正常，false错误
    private String status; //202状态码为登录过期

    public ReturnObject() {
        super();
    }

    /**
     * 返回正常数据 code为1
     *
     * @param message 返回的信息
     * @return
     */
    public static ReturnObject success(String message) {
        return new ReturnObject<Object>(ReturnStatus.returnSuccess, message);
    }


    /**
     * 返回正常数据 code为1
     *
     * @param data 返回的数据
     * @return
     */
    public static ReturnObject success(Object data) {
        return new ReturnObject<Object>(ReturnStatus.returnSuccess, data);
    }

    /**
     * 返回正常数据 code为1
     *
     * @param data    返回的数据
     * @param message 返回提示信息
     * @return
     */
    public static ReturnObject success(Object data, String message) {
        return new ReturnObject<Object>(ReturnStatus.returnSuccess, message, data);
    }

    /**
     * 返回错误数据
     *
     * @param message 错误信息
     * @return
     */
    public static ReturnObject fail(String message) {
        return new ReturnObject<Object>(ReturnStatus.returnFalse, message, null, String.valueOf(ReturnStatus.STATUS_GLOBAL_WARN_MESSAGE));
    }

    /**
     * 返回错误数据
     *
     * @param message 错误信息
     * @return
     */
    public static ReturnObject fail(String message, String status) {
        return new ReturnObject<Object>(ReturnStatus.returnFalse, message, "", status);
    }

    /**
     * 返回操作状态码，及操作信息 使用场景： 错误返回提示 例：statuts = -2 message = "数据格式有误，请校验后重新提交"
     *
     * @param result
     * @param message
     */
    public ReturnObject(String result, String message) {
        this.result = result;
        this.message = message;
    }

    /**
     * 其他全返回格式场景
     *
     * @param result
     * @param message
     * @param data
     */
    public ReturnObject(String result, String message, T data) {
        this.result = result;
        this.message = message;
        this.data = data;
    }

    /**
     * 其他全返回格式场景
     *
     * @param result
     * @param message
     * @param data
     */
    public ReturnObject(String result, String message, T data, String status) {
        this.result = result;
        this.message = message;
        this.data = data;
        this.status = status;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    /**
     * 返回操作状态码及数据
     *
     * @param result
     * @param data
     */
    public ReturnObject(String result, T data) {
        this.result = result;
        this.data = data;
    }

    /**
     * 操作成功，直接返回返回成功信息
     *
     * @param message
     */
    public ReturnObject(String message) {
        this.result = ReturnStatus.returnSuccess;
        this.message = message;
    }

    /**
     * 操作成功，直接返回返回数据
     *
     * @param data
     */
    public ReturnObject(T data) {
        this.result = ReturnStatus.returnSuccess;
        this.data = data;
    }

    /**
     * 操作成功，返回成功信息及成功数据
     *
     * @param data
     * @param message
     */
    public ReturnObject(T data, String message) {
        this.result = ReturnStatus.returnSuccess;
        this.data = data;
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public String getMessage() {
        return message;
    }


    public void setData(T data) {
        this.data = data;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public String getResult() {
        return result;
    }

    public void setResult(String result) {
        this.result = result;
    }


}
